#include "mathprolib.h"
#ifndef _STDIO_H_
#include <stdio.h>
#endif
typedef struct geribgiyuerbiyuebrgiubew{
    long long numerator;
    long long denominator;
}Fraction;
typedef struct 
long long gcd(long long m,long long n){
        int mm,nn;
        mm = (int)(m/abs(m));
        m = abs(m);
        nn = (int)(m/abs(m));   
        n = abs(n);
        for(i=n; i>0; i--){
                if(m%i==0 && n%i==0)return i*mm*nn;
        }
}//gcd、lcm仅这个文件使用
long long lcm(long long a,long long b){
        return a * b / gcd(a,b);
}
long long abs(long long num){
    return (long long)((unsigned long long)num);
}
void reduction(Fraction *a,short number){
        if(*a.numerator%number == 0&&*a.denominator == 0){
                printf("redution failed.cannot reduction by %d",number)
                return;
        }
        else{
                *a.numerator = *a.numerator / number
                *a.denominator = *a.denominator / number
        }                                      
}
void reduction(Fraction *a){
        long long times = gcd(*a.numerator,*a.denominator);
        *a.numerator = *a.numerator/times;
        *a.denominator = *a.denominator/times;
        return;
}
void reduction(Fraction *a,Fraction *b){
        
        long long times1 = lcm(*a.denominator,*b.denominator)/ *a.denominator;
        long long times2 = lcm(*a.denominator,*b.denominator)/ *b.denominator;
        *a.numerator = *a.numerator*times1;
        *a.denominator = *a.denominator*times1;
        *b.numerator = *b.numerator*times2;
        *b.denominator = *b.denominator*times2;
        return;
}

Fraction add(Fraction a,Fraction b){
        Fraction *k,*m;
        k = &k;
        m = &m;
        reduction(k,m);
        Fraction tmp = {*k.numerator + *m.numerator,*k.denominator};
        reduction(tmp);
        return tmp;
}
Fraction sub(Fraction a,Fraction b){
        Fraction *k,*m;
        k = &k;
        m = &m;
        reduction(k,m);
        Fraction tmp = {*k.numerator - *m.numerator,*k.denominator}; 
        reduction(tmp);
        return tmp;
}
Fraction* Make(long long numerator,long long denominator){
        static struct Fraction result = {numerator,denominator};
        return &result;
} 
Fraction mul( Fraction a,Fraction b){
        Fraction *m;
        m = Make(a.numerator*b.numerator,a.denominator*b.denominator);
        reduction(m)
}
void rec(Fraction *p){
        long long tmp = *p.numerator;
        *p.numerator = *p.denominator;
        *p.denominator = tmp;
}
Fraction div(Fraction a,Fraction b){
        Fraction tmp = mul(a,b);
        rec(&tmp);
        reduction(&tmp);
        return tmp;
}